/**
 * Lenovo Group
 * Copyright (c) 1999-2016 All Rights Reserved.
 */
package com.lenovo.lmrp.api.itsmgateway;

import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import com.lenovo.lmrp.api.model.RestResponse;
import com.lenovo.lmrp.api.model.entity.ProjectPO;
import com.lenovo.lmrp.api.model.entity.TicketPO;
import com.lenovo.lmrp.api.model.view.AttachmentVO;
import com.lenovo.lmrp.api.model.view.ChangedTicketVO;
import com.lenovo.lmrp.api.model.view.PartsVO;
import com.lenovo.lmrp.api.model.view.TicketVO;
import com.lenovo.sdc.framework.util.PageData;

/**
 * 
 * @author wujin
 */
@Consumes("application/json;charset-utf-8")
@Produces("application/json;charset-utf-8")
public interface IItsmTicket {
    
    /**
     * Get one ITSM ticket according to ticket ID.
     * 
     * @param itsmCode
     * @param ticketID
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/{ticketid}")
    public RestResponse<TicketVO> getTicket(@PathParam("itsmcode") String itsmCode, 
                                            @PathParam("ticketid") String ticketID);
    
    
    /**
     * find ticket by ticket id,status,title,projectname,country,city,assignee,assignedgroup,time
     * 
     * @param itsmCode
     * @param id
     * @param projectname
     * @param status
     * @param pageVo
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/list")
    public RestResponse<PageData<TicketPO>> listTicket(@PathParam("itsmcode") String itsmCode, 
            @QueryParam("id") String id,
            @QueryParam("projectName") String projectName,
            @QueryParam("status") String status,
            @QueryParam("page") int page,
            @QueryParam("limit") int rows);
    /**
     * Create inspection ticket and sync to ITSM system. That needn't to go throught workflow, status is closed directly
     * 
     * @param itsmCode
     * @param ticket
     * @return
     */
    @POST
    @Path("/{itsmcode}/tickets")
    public RestResponse<String> openTicket(@PathParam("itsmcode") String itsmCode, TicketVO ticket);
    
    /**
     * Update ticket data step by step in workflow and sync to ITSM system.
     * 
     * @param itsmCode
     * @param ticketid
     * @param action
     * @param changedTicketVO
     * @return
     */
    @PUT
    @Path("/{itsmcode}/tickets/{ticketid}/{action}")
    public RestResponse<Integer> updateTicket(@PathParam("itsmcode") String itsmCode,
                                              @PathParam("ticketid") String ticketid,
                                              @PathParam("action") String action,
                                              ChangedTicketVO changedTicketVO);
    
    /**
     * Create attachment record first, that status in Unupload. Engineer can upload file later, 
     * system will trace attachment file status, sync uploaded file to ITSM.
     * 
     * @param itsmcode
     * @param ticketid
     * @param attachmentVO
     * @return
     */
    @POST
    @Path("/{itsmcode}/tickets/{ticketid}/attachments/info")
    public RestResponse<String> createAttachment(@PathParam("itsmcode") String itsmcode,
                                                 @PathParam("ticketid") String ticketid,
                                                 AttachmentVO attachmentVO);
    
    /**
     * Update attachment status, submitter, store path or CDN path. If file has synced to ITSM, ignore any change!
     * 
     * @param itsmCode
     * @param ticketid
     * @param attachmentid
     * @param attachmentVO
     * @return
     */
    @PUT
    @Path("/{itsmcode}/tickets/{ticketid}/attachments/{attachmentid}")
    public RestResponse<Integer> updateAttachment(@PathParam("itsmcode") String itsmCode,
                                                  @PathParam("ticketid") String ticketid,
                                                  @PathParam("attachmentid") String attachmentid,
                                                  AttachmentVO attachmentVO);
    
    /**
     * list attachment files of one ticket, filter by status
     * query parameter is: status={status}&type={types}
     * 
     * Status defined in AttachmentStatus,
     * @param itsmDode
     * @param ticketid
     * @param status    if value is -1, return all attachment
     * @param types     separated by ',', -1 means all type
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/{ticketid}/attachments/q")
    public RestResponse<List<AttachmentVO>> listAttachment(@PathParam("itsmcode") String itsmCode, 
                                                                  @PathParam("ticketid") String ticketid,
                                                                  @QueryParam("status") int status,
                                                                  @QueryParam("types") String type);
    
    /**
     * Query special attachment record of one ticket
     * Attachment file real loation in path field, can download base on url field value
     * 
     * @param itsmDode
     * @param ticketid
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/{ticketid}/attachments/{attachmentid}")
    public RestResponse<AttachmentVO> getAttachment(@PathParam("itsmcode") String itsmCode,
                                                            @PathParam("ticketid") String ticketid,
                                                            @PathParam("attachmentid") String attachmentid);
    
    /**
     * Trigger system to sync attachment file with ITSM. Return the number of unsynced file
     * 
     * @param itsmCode
     * @param ticketid
     * @return
     */
    @POST
    @Path("/{itsmcode}/tickets/{ticketid}/attachments?act=sync")
    public RestResponse<Integer> syncAttachment(@PathParam("itsmcode") String itsmCode, 
                                                @PathParam("ticketid") String ticketid);
    
    /**
     * get one special ticket parts by partnum. 
     * In our system partnum is union
     * 
     * @param itsmCode
     * @param ticketid
     * @param partnum
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/{ticketid}/parts/{partnum}")
    public RestResponse<PartsVO> getParts(@PathParam("itsmcode") String itsmCode,
        @PathParam("ticketid") String ticketid,
        @PathParam("partnum") String partnum);
    

    /**
     * Obtain ticket parts list
     * 
     * @param itsmCode
     * @param ticketid
     * @return
     */
    @GET
    @Path("/{itsmcode}/tickets/{ticketid}/parts")
    public RestResponse<List<PartsVO>> listParts(@PathParam("itsmcode") String itsmCode, @PathParam("ticketid") String ticketid);
    
    /**
     * For some ticket, customer machine need to change parts, so need to create changed parts record first.
     * Sometimes, engineer need upload parts picture, they should invoke attachment interfaces. 
     * 
     * @param itsmcode
     * @param ticketid
     * @param parts
     * @return
     */
    @POST
    @Path("/{itsmcode}/{ticketid}/parts")
    public RestResponse<Integer> replaceParts(@PathParam("itsmcode") String itsmcode,
                                              @PathParam("ticketid") String ticketid,
                                              List<PartsVO> parts);
    
    @PUT
    @Path("/{itsmcode}/updatetickets/{ticketid}")
    public RestResponse<Integer> updateTicketExtense(@PathParam("itsmcode") String itsmcode,
    												@PathParam("ticketid") String ticketid,
    												Map<String, Object> extense);
    
    /**
     * return ticket's  extension data
     * 
     * @param itsmCode
     * @param ticketid
     * @return
     */
    @GET
    @Path("/{itsmcode}/ticketsExt/{ticketid}")
    public RestResponse<TicketPO> getTicketExt(@PathParam("itsmcode") String itsmCode, 
                                              @PathParam("ticketid") String ticketid);
}
